Creating new theme in orchard with codegeneration module - c#

I was following the documentation on this OrchardProject.net link. I opened have activated the CodeGeneration module and opened the command prompt at the root of the project (Orchard.Web) and write "bin/Orchard.exe" for running the commands. Till then everything is fine. Now when I try to run the following command, it gives me the below exception. The command is:
codegen theme mishrajiTheme /BasedOn:TheThemeMachine /CreateProject:true /IncludeInSolution:true
Below is the output of the command.
Creating Theme
mishrajiTheme
Error executing command "codegen theme mishrajiTheme"
Specified argument was out of the range of valid values. Parameter
name: startIndex
Exception Details: System.ArgumentOutOfRangeException: Specified
argument was out of the range of valid values. Parameter name:
startIndex
Stack Trace:
[ArgumentOutOfRangeException: Specified argument was out of the range
of valid values. Parameter name: startIndex] at
System.String.Insert(Int32 startIndex, String value) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.AddToSolution(TextWriter
output, String projectName, String projectGuid, String
containingFolder, String solutionFolderGuid) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.CreateThemeFromTemplates(TextWriter
output, String themeName, String baseTheme, String projectGuid,
Boolean includeInSolution) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.IntegrateTheme(String
themeName, String baseTheme) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.CreateTheme(String
themeName)
What I am doing wrong here or It is a bug in Orchard code generation module.
Please guide. I am using Orchard 1.10 version.

I solved this problem by changing the CodeGenerationCommands Class in line 434 in Orchard 1.10. the line is :
solutionText = solutionText.Insert(solutionText.LastIndexOf("EndProject\r\n"), projectReference);
to this :
solutionText = solutionText.Insert(solutionText.LastIndexOf("EndProject\n"), projectReference);
i don't know why by \r\n can not found the final EndProject and by changing that to \n it works fine

The line of code in question that has failed is this:
solutionText = solutionText.Insert(solutionText
.LastIndexOf("EndProject\r\n"),projectReference)
.Replace("GlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n",
projectConfiguationPlatforms);
If solutionText.LastIndexOf("EndProject\r\n") doesn't find anything it will return -1 - see the MSDN docs here.
It looks like that is then being passed to the string.Insert which is an invalid out of index.
The only thing that I can think is that your git client or however you got your hands on the orchard source has somehow changed the line endings in the file so it can't find the \r\n.
I'm guessing you are from the indian subcontinent, is your OS running a non-english language? I don't think that the .sln file localises fields like EndProject and I don't think Windows varies its newline character representation but something is going wrong here.
Workaround Solution
This is the very last thing that the codegen theme command does, it has created everything else and just failed to add your project into the Orchard.sln. To get moving right now you can just add it to your solution:
In visual studio, open solution explorer window
Right click on your Themes solution folder
Click Add | Existing project
Navigate to the folder and select your new theme
Potential Bug
It seems like there could be a bug here. Would you be willing to post your .sln file to me via email so I can investigate it further?

Related

Remove   - (non-breaking space) - added somehow in binded value on a GridView

I'm working on a C# Web Application project built in framework 3.5 where - for some odd reason I haven't figured out - the   - (non-breaking space) is added.
This is the scenario:
I query certain data that is binded in a GridView. One of the values returned from the database is:
04/03/2013 12:00:00 a.m.
Screenshot shows the value is returned correctly:
But, when this value is binded - i.e: GvEmployee.DataBind(); - in the "RowDataBound" event of the GridView called "GvEmployee", the value is shown as:
4/03/2013 12:00:00 a. m. - note the non-breaking space added.
and the System.FormatException exception occurs:
System.FormatException: 'String was not recognized as a valid
DateTime.'
This error is due the non-breaking space and the a.m. additional string. If I remove those characters - while debugging at runtime - , the DateTime conversion can be done.
This the code where the error occurs:
protected void GvEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
{
string id; // This is a reusable variable.
// Check rows only:
if (e.Row.RowIndex >= 0)
{
// Get the value stored in the given cell at the row:
id = e.Row.Cells[3].Text;
// Here, the value of "id" variable is: "4/03/2013 12:00:00 a. m.".
// But, the value returned by the database is: "04/03/2013 12:00:00 a.m.".
// Check if the "id" variable is not empty...
if (!id.Equals(" ") && !string.IsNullOrEmpty(id))
{
// Here fails, due to the value of "id" variable, that is: "4/03/2013 12:00:00 a. m."
// isn't recognized as a valid DateTime value.
e.Row.Cells[3].Text = Convert.ToDateTime(id, CultureInfo.CurrentCulture).ToShortDateString();
}
}
}
As you can see, the non-breaking space on the string value:
This is very strange since this project is already published and only happens on my notebook - I believe there is some missing configuration in the notebook I'm using for work on this project, but, I haven't found any clue about what that could be - I didn't know about non-breaking spaces until this problem happens to me and I found this answer on Stack Overflow...
I've searched about the root of this issue and I tried solving this by adding in the Global.asax the configuration shown in this source and added here for clarity:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
System.Globalization.CultureInfo newCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
newCulture.DateTimeFormat.AMDesignator = "";
newCulture.DateTimeFormat.LongDatePattern = "dd/MM/yyyy";
newCulture.DateTimeFormat.LongTimePattern = "HH:mm:ss";
newCulture.DateTimeFormat.PMDesignator = "";
newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
newCulture.DateTimeFormat.TimeSeparator = ":";
newCulture.DateTimeFormat.DateSeparator = "/";
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture;
}
and searched about how to remove those non-breaking spaces globally = by changing some configuration in the web.config and/or the Global.asax of the project, but, nothing so far that worked.
Other alternatives found are about using regex for removing the problematic characters, but, I'm looking for a global setting to apply - due to this situation happens in all the project - not just one page and not only with the given datetime value posted above, and, I have checked the response from the database and it's correct - the problem must be in the ASP.NET C# Web project, but, I don't know exactly where and why this is happening.
I don't know what else it could be, maybe is the language of the operating system?, or the Culture settings of the computer?...
I'm out of ideas, any help is appreciated.
tl;dr: I applied these changes and settings in Visual Studio - not sure which one is the one who applied the solution to this issue, but, I'll leave it as is - since it worked for me:
Discard the changes I made in the Global.asax file that I described in my question.
Uncheck the Save documents as Unicode when data cannot be saved in codepage option found in this path: Tools > Options > Environment > Documents - credits to this answer.
Download the latest version of the problematic aspx/ascx file from the Source Control - (this project is on TFS) - overwriting the local files1.
Applied this line of code on the Site.master of the solution: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> - credits to this answer.
1 I forgot mention that this project is on TFS and when I downloaded the project on this notebook, I got this warning:
"This file contains characters in Unicode format which will be lost if
you save this file as an ANSI encoded text file. To keep the Unicode
information, click cancel below and then select one of the Unicode
options from the Encoding drop-down list. Do you want to continue?"
OK / Cancel
Source of the image
I ignored that warning and I think I select OK -> I think this is the root of the problem.
Long version: The project I'm working is on TFS; when I downloaded the project in the notebook - which is a brand new one - I remember I got the warning that says:
This file contains characters in Unicode format which will be lost if you save this file as an ANSI encoded text file. To keep the Unicode information, click Cancel below and then select one of the Unicode options from the Encoding drop down list. Continue?
I selected OK - if I recall correctly - and the project downloading continued without more warnings.
When I compiled all parts of the project and execute it, all was good - until I came to retrieve some data - for check if all was working fine (since this project uses Oracle as database and in my experience with this project and Oracle is that sometimes, unexpected errors presents) and I got the error I described in the question.
After trying all I could possibly could think of, suddenly I remembered this warning I got when I download the project.
Then, I start searching about how check the encoding of the files in the project and I got this answer (1) - this answer (2) looked promising too, but, when I tried and - as I understand - the first linked answer says to make those steps file by file, manually = which is not viable; about the second linked answer, I could not find the location in the .sln or .csproj file.
I keep searching and added visual studio check aspx encoding on Google, one of the answers was this answer and I added the line on the Site.master of the project - since all pages uses this Master Page:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
When I did execute the solution/project, the non-breaking spaces where gone and the DateTime conversion was successful as is shown in this screenshot:

Revit API: Use String as Button Assembly Name with Current Path

I'm not entirely sure at all why this is happening...
So I have a ExternalCommand and an application for making a ribbon tab and button. These two programs are in the same solution and under the same namespace, which allows me to have fewer files to deal with. When I create a button for my command, I want to put in the current path of the application that is currently running. I do this with Directory.GetCurrentDirectory() + \AddInsAll\Ribbon17.dll (where AddInsAll is the folder and Ribbon17 is the dll, obviously). I use # when necessary to avoid escape sequences. This string contains the exact assembly name needed, but Revit tells me "Assembly does not exist." If I replace this String variable with the hard coded C:\ProgramData\Autodesk\Revit\Addins\2017\AddInsAll\Ribbon17.dll it works. I want it obviously more robust than that. My code will be below, thanks in advance.
FYI: I have a TaskDialog showing when it first runs, and the fullPath that it returns is exacly the same as the hard coded path. I have to do a replace (Program Files to ProgramData) due to some weird bug with the get directory. Also, I add "\AddInsAll\Ribbon17.dll" to the end of the string because the CurrentDirectory goes only to Addins\2017. Finally, if you think the problem is due to the #'s, I have already tried putting it and taking it off of variables and none of the attempts work. But if you think of them is the problem, I welcome the advice. Thanks.
public class RibApp : IExternalApplication
{
public Result OnStartup(Autodesk.Revit.UI.UIControlledApplication application)
{
// Create a custom ribbon tab
String tabName = "Add-Ins";
String fakeFullPath = #Directory.GetCurrentDirectory() + #"\AddInsAll\Ribbon17.dll";
String fullPath = fakeFullPath.Replace(#"\Program Files\", #"\ProgramData\");
TaskDialog.Show("Hi", #fullPath);
application.CreateRibbonTab(tabName);
//Create buttons and panel
// Create two push buttons
PushButtonData CommandButton = new PushButtonData("Command17", "Command",
#fullPath, "Ribbon17.Command");
I suggest you skip the # and replace each backslash \ by a forward slash /.
KISS!
Better still, use an approach similar to the CreateRibbonTab implementation in the HoloLens Escape Path Waypoint JSON Exporter.

0x3 error using pdbstr (Source indexing)

I am trying to use the PDBSTR.EXE tool to merge version information into a PDB file and from time to time I encounter the following error:
[result: error 0x3 opening K:\dev\main\bin\mypdbfile.pdb] <- can be a different PDB file.
An example of the command line that I use is:
pdbstr.exe -w -s:srcsrv -p:K:\dev\main\bin\mypdbfile.pdb -i:C:\Users\username\AppData\Local\Temp\tmp517B.stream
Could you tell me what would cause error code 0x3?
If the error code is similar to the standard System error code 3 ERROR_PATH_NOT_FOUND, then it seems to think that the path K:\dev\main\bin\mypdbfile.pdb does NOT exist when in fact it DOES.
However please note that my K: drive is a SUBST'ed drive.
(System error code reference https://msdn.microsoft.com/en-ca/library/windows/desktop/ms681382(v=vs.85).aspx)
Do you know what the 0x3 error code could possibly mean?
If this error code appears from time to time, then i guess the ERROR_PATH_NOT_FOUND might be the real problem.
I guess the cause is, i couldn't see any double quotes wrapping the path you've given as input. When the path contains a folder name with spaces in it, it breaks your path. For ex
pdbstr.exe -w -s:srcsrv -p:K:\dev\main\my folder with spaces\mypdbfile.pdb -i:C:\Users\username\AppData\Local\Temp\tmp517B.stream
Add a double quote around the path and that might solve it. Hope it helps.

Calling RubyScript via IronRuby with command line parameters or arguments

We're pretty new to Ruby and very new to IronRuby so please bear with me. We're in C# trying to do something very simple. I've got a ruby script called doExtract.rb and I need to pass it a file called myfile.txt. We've copied all the files required into the /bin folder of the build and they run correctly when called via the command line.
var rubyRuntime = Ruby.CreateRuntime();
var rubyEngine = rubyRuntime.GetEngine("rb");
String fullPath = String.Format("{0} {1}", "doExtract.rb", "myfile.txt");
rubyEngine.ExecuteFile(fullPath);
gives me an error of "Illegal characters in path"
I've searched high & low on the t'interwebs and to no avail.
We've tried adding the search paths to the rubyEngine and using a full path to the myfile.txt but still get the error. If we call a simple ruby script with no parameters then it works fine. We've also tried with escaped slashed both backwards and forwards in the myfile.txt. I'm sure it'd something really stupid that we're not doing !
Any suggestions where we're going wrong ?
Thanks

Visual Studio Installer > PostBuildEvent error code '1'

I'm trying to run a .js file with PostBuildEvent in Visual Studio 2010 and fail when i build the solution with the error code
Error 2 'PostBuildEvent' failed with error code '1' 'Error no especificado'
I already check the names of the files, the path, and the code in my project and js file, and everything seems right...
the js file contain this
// http://blogs.msdn.com/b/heaths/archive/2006/02/01/64-bit-managed-custom-actions-with-visual-studio.aspx
var msiOpenDatabaseModeTransact = 1;
var msiViewModifyUpdate = 2
var filespec = WScript.Arguments(0);
var projdir = WScript.Arguments(1);
var installer = WScript.CreateObject("WindowsInstaller.Installer");
var database = installer.OpenDatabase(filespec, msiOpenDatabaseModeTransact);
// Update the Binary table...
var sql = "SELECT `Name`,`Data` FROM `Binary` where `Binary`.`Name` = 'InstallUtil'";
var view = database.OpenView(sql);
view.Execute();
var record = view.Fetch();
record.SetStream(2, projdir + "InstallUtilLib.dll");
view.Modify(msiViewModifyUpdate, record);
view.Close();
database.Commit();
Anyone already solve a problem like this??
Any help, please...
Since you are using Visual Studio Installer, location of JS File is also important. Your js file should be in the same directory as the .vdproj file for your setup project.
This should be of some help to you
http://blogs.msdn.com/b/astebner/archive/2006/08/12/696833.aspx
In a desperate attempt to solve the problem, I found the solution.
After checking everything else, i move my project to another folder, and I discovered that the path was too long.
The path of my project, despite having less than 255 characters, as indicated by the Microsoft site, cause the Visual Studio 2010 give back this error.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
But attention, being a little explanatory error may result from other errors in other cases. In my case solved the problem.

Categories

Resources