Exemplo n.º 1
0
        private string GetRelativeClassName(string sourceTypeName, bool isInterface)
        {
            string relativeClassName = null;

            foreach (var trans in this.translations)
            {
                if (sourceTypeName.StartsWith(trans.Key))
                {
                    relativeClassName = trans.Value + sourceTypeName.Substring(trans.Key.Length);
                }
            }

            if (isInterface)
            {
                relativeClassName = relativeClassName == null
                                        ? "I"
                                        : relativeClassName.Insert(relativeClassName.LastIndexOf('.') + 1, "I");
            }

            if (relativeClassName == null)
            {
                throw new InvalidOperationException("No translation found for namespace for " + sourceTypeName);
            }

            string[] names = relativeClassName.Split('.')
                             .Select(x => String.Concat(x.Substring(0, 1).ToUpper(), x.Substring(1)))
                             .ToArray();

            relativeClassName = String.Join(".", names);

            return(relativeClassName);
        }
Exemplo n.º 2
0
        public static PublishPackageViewModel FromLocalPackage(Package l)
        {
            var vm = new PublishPackageViewModel(dynSettings.PackageManagerClient)
            {
                Group       = l.Group,
                Description = l.Description,
                Keywords    = l.Keywords != null?String.Join(" ", l.Keywords) : ""
            };

            vm.FunctionDefinitions =
                l.LoadedCustomNodes.Select(x => dynSettings.CustomNodeManager.GetFunctionDefinition(x.Guid)).ToList();

            if (l.VersionName != null)
            {
                var parts = l.VersionName.Split('.');
                if (parts.Count() == 3)
                {
                    vm.MajorVersion = parts[0];
                    vm.MinorVersion = parts[1];
                    vm.BuildVersion = parts[2];
                }
            }

            vm.Name    = l.Name;
            vm.Package = l;

            return(vm);
        }
Exemplo n.º 3
0
        public static PublishPackageViewModel FromLocalPackage(DynamoViewModel dynamoViewModel, Package l)
        {
            var vm = new PublishPackageViewModel(dynamoViewModel)
            {
                Group       = l.Group,
                Description = l.Description,
                Keywords    = l.Keywords != null?String.Join(" ", l.Keywords) : "",
                                  FunctionDefinitions =
                                      l.LoadedCustomNodes.Select(
                                          x => dynamoViewModel.Model.CustomNodeManager.GetFunctionDefinition(x.Guid))
                                      .ToList(),
                                  Name    = l.Name,
                                  Package = l
            };

            if (l.VersionName == null)
            {
                return(vm);
            }

            var parts = l.VersionName.Split('.');

            if (parts.Count() != 3)
            {
                return(vm);
            }

            vm.MajorVersion = parts[0];
            vm.MinorVersion = parts[1];
            vm.BuildVersion = parts[2];
            return(vm);
        }
Exemplo n.º 4
0
        private IEnumerable <string> GetAllFiles()
        {
            // get all function defs
            var allFuncs = AllFuncDefs().ToList();

            // all workspaces
            var workspaces = allFuncs.Select(def => def.WorkspaceModel).ToList();

            // make sure workspaces are saved
            var unsavedWorkspaceNames =
                workspaces.Where(ws => ws.HasUnsavedChanges || ws.FileName == null).Select(ws => ws.Name).ToList();

            if (unsavedWorkspaceNames.Any())
            {
                throw new Exception("The following workspaces have not been saved " +
                                    String.Join(", ", unsavedWorkspaceNames) + ". Please save them and try again.");
            }

            // omit files currently already under package control
            var files =
                allFuncs.Select(f => f.WorkspaceModel.FileName)
                .Where(p =>
                       (dynSettings.PackageLoader.IsUnderPackageControl(p) &&
                        dynSettings.PackageLoader.GetOwnerPackage(p).Name == this.Name) || !dynSettings.PackageLoader.IsUnderPackageControl(p));

            // union with additional files
            files = files.Union(this.AdditionalFiles);

            return(files);
        }
Exemplo n.º 5
0
 /// <summary>
 ///     The class constructor - use this constructor for built-in types\
 ///     that are not yet loaded.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="description"></param>
 /// <param name="tags"></param>
 public NodeSearchElement(string name, string description, IEnumerable <string> tags)
 {
     this.Node         = null;
     this._name        = name;
     this.Weight       = 1;
     this.Keywords     = String.Join(" ", tags);
     this._type        = "Node";
     this._description = description;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Save the file into target.import
        /// </summary>
        public void SaveImportFile()
        {
            // put new paths into doc
            XmlNode node = Doc.DocumentElement?.GetElementsByTagName("SearchPath")[0];

            node.InnerText = String.Join(";\n", Paths) + ";";
            // save
            Doc.Save(ImportFilePath);
        }
Exemplo n.º 7
0
        public static PublishPackageViewModel FromLocalPackage(DynamoViewModel dynamoViewModel, Package l)
        {
            var vm = new PublishPackageViewModel(dynamoViewModel)
            {
                Group       = l.Group,
                Description = l.Description,
                Keywords    = l.Keywords != null?String.Join(" ", l.Keywords) : "",
                                  CustomNodeDefinitions =
                                      l.LoadedCustomNodes.Select(
                                          x => dynamoViewModel.Model.CustomNodeManager.GetFunctionDefinition(x.Guid))
                                      .ToList(),
                                  Name    = l.Name,
                                  Package = l
            };

            // add additional files
            l.EnumerateAdditionalFiles();
            foreach (var file in l.AdditionalFiles)
            {
                vm.AdditionalFiles.Add(file.Model.FullName);
            }

            // load assemblies into reflection only context
            foreach (var file in l.EnumerateAssemblyFiles())
            {
                Assembly assem;
                var      result = PackageLoader.TryReflectionOnlyLoadFrom(file, out assem);
                if (result)
                {
                    vm.Assemblies.Add(assem);
                }
                else
                {
                    // if it's not a .NET assembly, we load it as an additional file
                    vm.AdditionalFiles.Add(file);
                }
            }

            if (l.VersionName == null)
            {
                return(vm);
            }

            var parts = l.VersionName.Split('.');

            if (parts.Count() != 3)
            {
                return(vm);
            }

            vm.MajorVersion = parts[0];
            vm.MinorVersion = parts[1];
            vm.BuildVersion = parts[2];
            return(vm);
        }
Exemplo n.º 8
0
        protected override string FormatSelectionText <T>(IEnumerable <T> elements)
        {
            if (typeof(T) != typeof(Element))
            {
                return("");
            }

            var ids =
                elements.Cast <Element>().Where(el => el.IsValidObject).Select(el => el.Id).ToArray();

            return(ids.Any() ? String.Join(" ", ids.Take(20)) : "");
        }
Exemplo n.º 9
0
 private void buttonEdit_Click(object sender, EventArgs e)
 {
     // switch from listbox to text box
     listBoxPath.Visible = false;
     textBoxPath.Visible = true;
     // load paths into textbox
     textBoxPath.Clear();
     textBoxPath.Text = String.Join(";\r\n", ImportModel.Paths) + ";";
     textBoxPath.Focus();
     // enable save button
     buttonSave.Enabled = true;
 }
Exemplo n.º 10
0
        protected override string FormatSelectionText <T>(IEnumerable <T> elements)
        {
            var doc = DocumentManager.Instance.CurrentDBDocument;

            var ids =
                elements.Cast <Reference>()
                .Select(doc.GetElement)
                .Where(el => el != null)
                .Select(el => el.Id);

            return(ids.Any() ? String.Join(" ", ids.Take(20)) : "");
        }
Exemplo n.º 11
0
        private static TextExtractionResult assembleExtractionResult(string text, Metadata metadata)
        {
            var metaDataResult = metadata.names()
                                 .ToDictionary(name => name, name => String.Join(", ", metadata.getValues(name)));

            var contentType = metaDataResult["Content-Type"];

            return(new TextExtractionResult
            {
                Text = text,
                ContentType = contentType,
                Metadata = metaDataResult
            });
        }
Exemplo n.º 12
0
        /// <summary>
        /// Delegate used to submit the element</summary>
        private void Submit()
        {
            try
            {
                var newpkg = Package == null;

                Package = Package ?? new Package("", this.Name, this.FullVersion);

                Package.VersionName = FullVersion;
                Package.Description = Description;
                Package.Group       = Group;
                Package.Keywords    = KeywordList;

                var files = GetAllFiles().ToList();

                Package.Contents = String.Join(", ", GetAllNodeNameDescriptionPairs().Select((pair) => pair.Item1 + " - " + pair.Item2));

                if (ContainsBinaries)
                {
                    Package.Contents = Package.Contents + PackageManagerClient.PackageContainsBinariesConstant;
                }
                if (ContainsPythonScripts)
                {
                    Package.Contents = Package.Contents + PackageManagerClient.PackageContainsPythonScriptsConstant;
                }

                Package.Dependencies.Clear();
                GetAllDependencies().ToList().ForEach(Package.Dependencies.Add);

                if (newpkg)
                {
                    this.dynamoViewModel.Model.Loader.PackageLoader.LocalPackages.Add(Package);
                }

                var handle = this.dynamoViewModel.Model.PackageManagerClient.Publish(Package, files, IsNewVersion);

                if (handle == null)
                {
                    throw new Exception("Failed to authenticate.  Are you logged in?");
                }

                this.Uploading    = true;
                this.UploadHandle = handle;
            }
            catch (Exception e)
            {
                ErrorString = e.Message;
                this.dynamoViewModel.Model.Logger.Log(e);
            }
        }
Exemplo n.º 13
0
        public static PublishPackageViewModel FromLocalPackage(DynamoViewModel dynamoViewModel, Package l)
        {
            var vm = new PublishPackageViewModel(dynamoViewModel)
            {
                Group       = l.Group,
                Description = l.Description,
                Keywords    = l.Keywords != null?String.Join(" ", l.Keywords) : "",
                                  CustomNodeDefinitions =
                                      l.LoadedCustomNodes.Select(
                                          x => dynamoViewModel.Model.CustomNodeManager.GetFunctionDefinition(x.Guid))
                                      .ToList(),
                                  Assemblies = l.LoadedAssemblies.ToList(),
                                  Name       = l.Name,
                                  Package    = l
            };

            // add additional files
            l.EnumerateAdditionalFiles();
            foreach (var file in l.AdditionalFiles)
            {
                vm.AdditionalFiles.Add(file.Model.FullName);
            }

            // add unloaded assemblies, that are not yet loaded
            var unloadedAssemblies =
                l.EnumerateAssemblyFiles()
                .Where(x => !l.LoadedAssemblies.Select(a => a.Location).Contains(x));

            foreach (var file in unloadedAssemblies)
            {
                vm.Assemblies.Add(Assembly.ReflectionOnlyLoadFrom(file));
            }

            if (l.VersionName == null)
            {
                return(vm);
            }

            var parts = l.VersionName.Split('.');

            if (parts.Count() != 3)
            {
                return(vm);
            }

            vm.MajorVersion = parts[0];
            vm.MinorVersion = parts[1];
            vm.BuildVersion = parts[2];
            return(vm);
        }
Exemplo n.º 14
0
        public static Dictionary <string, string> Tags()
        {
            var tag = TagLib.File.Create(music_File.AbsolutePath);

            Dictionary <string, string> MusicTags = new Dictionary <string, string>()
            {
                { "Title", music_File.Name },
                { "Performer", String.Join(", ", tag.Tag.Performers) },
                { "Album", tag.Tag.Album },
                { "Year", (tag.Tag.Year).ToString() },
                { "Gengres", String.Join(", ", tag.Tag.Genres) },
                { "Bitreit", tag.Properties.AudioBitrate.ToString() }
            };

            return(MusicTags);
        }
Exemplo n.º 15
0
        private IEnumerable <string> GetAllFiles()
        {
            // get all function defs
            var allFuncs = AllFuncDefs().ToList();

            // all workspaces
            var workspaces = new List <CustomNodeWorkspaceModel>();

            foreach (var def in allFuncs)
            {
                CustomNodeWorkspaceModel ws;
                if (dynamoViewModel.Model.CustomNodeManager.TryGetFunctionWorkspace(
                        def.FunctionId,
                        DynamoModel.IsTestMode,
                        out ws))
                {
                    workspaces.Add(ws);
                }
            }

            // make sure workspaces are saved
            var unsavedWorkspaceNames =
                workspaces.Where(ws => ws.HasUnsavedChanges || ws.FileName == null).Select(ws => ws.Name).ToList();

            if (unsavedWorkspaceNames.Any())
            {
                throw new Exception(Wpf.Properties.Resources.MessageUnsavedChanges0 +
                                    String.Join(", ", unsavedWorkspaceNames) +
                                    Wpf.Properties.Resources.MessageUnsavedChanges1);
            }

            var pmExtension = dynamoViewModel.Model.GetPackageManagerExtension();
            // omit files currently already under package control
            var files =
                workspaces.Select(f => f.FileName)
                .Where(
                    p =>
                    (pmExtension.PackageLoader.IsUnderPackageControl(p) &&
                     (pmExtension.PackageLoader.GetOwnerPackage(p).Name == Name) ||
                     !pmExtension.PackageLoader.IsUnderPackageControl(p)));

            // union with additional files
            files = files.Union(AdditionalFiles);
            files = files.Union(Assemblies.Select(x => x.Assembly.Location));

            return(files);
        }
Exemplo n.º 16
0
        public void SUTimeDefautTest()
        {
            var pipeline = new AnnotationPipeline();

            pipeline.addAnnotator(new PTBTokenizerAnnotator(false));
            pipeline.addAnnotator(new WordsToSentencesAnnotator(false));

            var tagger =
                new MaxentTagger(
                    Config.GetModel(@"pos-tagger\english-bidirectional\english-bidirectional-distsim.tagger"));

            pipeline.addAnnotator(new POSTaggerAnnotator(tagger));

            var sutimeRules = new[] {
                Config.GetModel(@"sutime\defs.sutime.txt"),
                Config.GetModel(@"sutime\english.holidays.sutime.txt"),
                Config.GetModel(@"sutime\english.sutime.txt")
            };

            var props = new Properties();

            props.setProperty("sutime.rules", String.Join(",", sutimeRules));
            props.setProperty("sutime.binders", "0");
            pipeline.addAnnotator(new TimeAnnotator("sutime", props));

            const string text       = "Three interesting dates are 18 Feb 1997, the 20th of july and 4 days from today.";
            var          annotation = new Annotation(text);

            annotation.set(new CoreAnnotations.DocDateAnnotation().getClass(), "2013-07-14");
            pipeline.annotate(annotation);

            Console.WriteLine(annotation.get(new CoreAnnotations.TextAnnotation().getClass()) + "\n");
            var timexAnnsAll = (ArrayList)annotation.get(new TimeAnnotations.TimexAnnotations().getClass());

            foreach (CoreMap cm in timexAnnsAll)
            {
                var tokens = (java.util.List)cm.get(new CoreAnnotations.TokensAnnotation().getClass());
                var first  = tokens.get(0);
                var last   = tokens.get(tokens.size() - 1);
                var time   = (TimeExpression)cm.get(new TimeExpression.Annotation().getClass());
                Console.WriteLine("{0} [from char offset '{1}' to '{2}'] --> {3}",
                                  cm, first, last, (time.getTemporal()));
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Delegate used to submit the element</summary>
        private void Submit()
        {

            try
            {
                var newpkg = Package == null;

                Package = Package ?? new Package("", this.Name, this.FullVersion);

                Package.VersionName = FullVersion;
                Package.Description = Description;
                Package.Group = Group;
                Package.Keywords = KeywordList;

                var files = GetAllFiles().ToList();

                Package.Contents = String.Join(", ", GetAllNodeNameDescriptionPairs().Select((pair) => pair.Item1 + " - " + pair.Item2));

                Package.Dependencies.Clear();
                GetAllDependencies().ToList().ForEach(Package.Dependencies.Add);

                if (newpkg) dynSettings.PackageLoader.LocalPackages.Add(Package);

                var handle = Client.Publish(Package, files, IsNewVersion);

                if (handle == null)
                    throw new Exception("Failed to authenticate.  Are you logged in?");

                this.Uploading = true;
                this.UploadHandle = handle;

            }
            catch (Exception e)
            {
                ErrorString = e.Message;
                dynSettings.Controller.DynamoLogger.Log(e);
            }

        }
Exemplo n.º 18
0
        public IEnumerable <String> WrapModule(String NamespaceName, List <String> Imports, IEnumerable <String> Contents)
        {
            yield return("//==========================================================================");

            yield return("//");

            yield return("//  Notice:      This file is automatically generated.");

            yield return("//               Please don't modify this file.");

            yield return("//");

            yield return("//==========================================================================");

            yield return("");

            if (NamespaceName != "")
            {
                var n = String.Join(".", NamespaceName.Split('.').Select(NamespacePart => LowercaseCamelize(NamespacePart)));
                foreach (var _Line in Combine(Combine(Combine(Begin(), "package "), n), ";"))
                {
                    yield return(_Line);
                }
                yield return("");
            }
            yield return("import niveum.lang.*;");

            foreach (var _Line in Combine(Combine(Combine(Begin(), "import "), Imports), ";"))
            {
                yield return(_Line);
            }
            yield return("");

            foreach (var _Line in Combine(Begin(), Contents))
            {
                yield return(_Line);
            }
            yield return("");
        }
Exemplo n.º 19
0
        internal string GetStringRepOfWorkspace()
        {
            // Create the xml document to write to.
            var document = new XmlDocument();

            document.CreateXmlDeclaration("1.0", null, null);
            document.AppendChild(document.CreateElement("Workspace"));

            //This is only used for computing relative offsets, it's not actually created
            string virtualFileName = String.Join(Path.GetTempPath(), "DynamoTemp.dyn");

            Utils.SetDocumentXmlPath(document, virtualFileName);

            if (!PopulateXmlDocument(document))
            {
                return(String.Empty);
            }

            //Now unset the temp file name again
            Utils.SetDocumentXmlPath(document, null);

            return(document.OuterXml);
        }
Exemplo n.º 20
0
        public static PublishPackageViewModel FromLocalPackage(DynamoViewModel dynamoViewModel, Package l)
        {
            var defs = new List <CustomNodeDefinition>();

            foreach (var x in l.LoadedCustomNodes)
            {
                CustomNodeDefinition def;
                if (dynamoViewModel.Model.CustomNodeManager.TryGetFunctionDefinition(
                        x.FunctionId,
                        DynamoModel.IsTestMode,
                        out def))
                {
                    defs.Add(def);
                }
            }

            var vm = new PublishPackageViewModel(dynamoViewModel)
            {
                Group       = l.Group,
                Description = l.Description,
                Keywords    = l.Keywords != null?String.Join(" ", l.Keywords) : "",
                                  CustomNodeDefinitions = defs,
                                  Name          = l.Name,
                                  RepositoryUrl = l.RepositoryUrl ?? "",
                                  SiteUrl       = l.SiteUrl ?? "",
                                  Package       = l,
                                  License       = l.License
            };

            // add additional files
            l.EnumerateAdditionalFiles();
            foreach (var file in l.AdditionalFiles)
            {
                vm.AdditionalFiles.Add(file.Model.FullName);
            }

            var nodeLibraryNames = l.Header.node_libraries;

            // load assemblies into reflection only context
            foreach (var file in l.EnumerateAssemblyFilesInBinDirectory())
            {
                Assembly assem;
                var      result = PackageLoader.TryReflectionOnlyLoadFrom(file, out assem);

                if (result)
                {
                    var isNodeLibrary = nodeLibraryNames == null || nodeLibraryNames.Contains(assem.FullName);
                    vm.Assemblies.Add(new  PackageAssembly()
                    {
                        IsNodeLibrary = isNodeLibrary,
                        Assembly      = assem
                    });
                }
                else
                {
                    // if it's not a .NET assembly, we load it as an additional file
                    vm.AdditionalFiles.Add(file);
                }
            }

            if (l.VersionName == null)
            {
                return(vm);
            }

            var parts = l.VersionName.Split('.');

            if (parts.Count() != 3)
            {
                return(vm);
            }

            vm.MajorVersion = parts[0];
            vm.MinorVersion = parts[1];
            vm.BuildVersion = parts[2];
            return(vm);
        }
Exemplo n.º 21
0
 private void AppendPackageContents()
 {
     Package.Contents = String.Join(", ", GetAllNodeNameDescriptionPairs().Select((pair) => pair.Item1 + " - " + pair.Item2));
 }
Exemplo n.º 22
0
        public IEnumerable <String> EventPump(List <ServerCommandDef> ServerCommands, String NamespaceName)
        {
            var ServerCommandGroups = ServerCommands.GroupBy(sc => sc.FullName()).Where(g => g.Any(sc => sc.Version == "")).ToList();

            yield return("private class EventPump : IEventPump");

            yield return("{");

            foreach (var g in ServerCommandGroups)
            {
                var c               = g.Where(sc => sc.Version == "").First();
                var Name            = c.GetTypeSpec().SimpleName(NamespaceName);
                var EventTypeString = GetSuffixedTypeString(c.Name, c.Version, "Event", NamespaceName);
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "public Action<"), EventTypeString), "> "), GetEscapedIdentifier(Name)), " { get; set; }"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
            }
            yield return("}");

            yield return("private IEventPump CreateEventPump(Func<List<String>, Func<String>> GetVersionResolver)");

            yield return("{");

            yield return("    var ep = new EventPump();");

            foreach (var g in ServerCommandGroups)
            {
                var c             = g.Where(sc => sc.Version == "").First();
                var Name          = c.GetTypeSpec().SimpleName(NamespaceName);
                var GroupCommands = g.ToList();
                if (GroupCommands.Count == 1)
                {
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Begin(), GetEscapedIdentifier(Combine(Combine(Begin(), "ep."), Name))), " = e => { if ("), GetEscapedIdentifier(Name)), " != null) { "), GetEscapedIdentifier(Name)), "(e); } };"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                }
                else
                {
                    var SortedGroupCommands = GroupCommands.Where(sc => sc.Version != "").OrderByDescending(sc => new NumericString(sc.Version)).ToList();
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "var "), GetEscapedIdentifier(Combine(Combine(Begin(), Name), "Resolver"))), " = GetVersionResolver(new List<String> { "), String.Join(", ", SortedGroupCommands.Select(sc => GetEscapedStringLiteral(sc.Version)))), " });"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    foreach (var _Line in Combine(Combine(Begin(), GetEscapedIdentifier(Combine(Combine(Begin(), "ep."), Name))), " = eHead =>"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "{");

                    foreach (var _Line in Combine(Combine(Combine(Begin(), "    var Version = "), GetEscapedIdentifier(Combine(Combine(Begin(), Name), "Resolver"))), "();"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "    if (Version == \"\")");

                    yield return("    " + "    {");

                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "        if ("), GetEscapedIdentifier(Name)), " != null) { "), GetEscapedIdentifier(Name)), "(eHead); }"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    yield return("    " + "        return;");

                    yield return("    " + "    }");

                    foreach (var sc in SortedGroupCommands)
                    {
                        var VersionedSimpleName = sc.GetTypeSpec().SimpleName(NamespaceName);
                        foreach (var _Line in Combine(Combine(Combine(Begin(), "if (Version == "), GetEscapedStringLiteral(sc.Version)), ")"))
                        {
                            yield return(_Line == "" ? "" : "        " + _Line);
                        }
                        yield return("        " + "{");

                        foreach (var _Line in Combine(Combine(Combine(Begin(), "    var e = "), GetEscapedIdentifier(Combine(Combine(Begin(), VersionedSimpleName), "EventFromHead"))), "(eHead);"))
                        {
                            yield return(_Line == "" ? "" : "        " + _Line);
                        }
                        foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    if ("), GetEscapedIdentifier(VersionedSimpleName)), " != null) { "), GetEscapedIdentifier(VersionedSimpleName)), "(e); }"))
                        {
                            yield return(_Line == "" ? "" : "        " + _Line);
                        }
                        yield return("        " + "    return;");

                        yield return("        " + "}");
                    }
                    yield return("    " + "    throw new InvalidOperationException();");

                    yield return("    " + "};");
                }
            }
            yield return("    return ep;");

            yield return("}");
        }
Exemplo n.º 23
0
        public IEnumerable <String> Translator_TupleTo(String VersionedSimpleName, String TypeString, String VersionedTypeString, List <TypeSpec> Elements, List <TypeSpec> HeadElements, String NamespaceName)
        {
            foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "public "), TypeString), " "), GetEscapedIdentifier(Combine(Combine(Begin(), VersionedSimpleName), "ToHead"))), "("), VersionedTypeString), " o)"))
            {
                yield return(_Line);
            }
            yield return("{");

            var k = 0;

            foreach (var eHead in HeadElements)
            {
                if (IsNullType(eHead))
                {
                    foreach (var _Line in Combine(Combine(Combine(Begin(), "var Item"), k + 1), " = new Unit();"))
                    {
                        yield return(_Line == "" ? "" : "    " + _Line);
                    }
                    k += 1;
                    continue;
                }
                if (k < Elements.Count)
                {
                    var e = Elements[k];
                    if (IsSameType(e, eHead, false))
                    {
                        foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "var Item"), k + 1), " = o.Item"), k + 1), ";"))
                        {
                            yield return(_Line == "" ? "" : "    " + _Line);
                        }
                        k += 1;
                        continue;
                    }
                    else if (IsSameType(e, eHead, true))
                    {
                        foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "var Item"), k + 1), " = "), GetEscapedIdentifier(Combine(Combine(Begin(), e.SimpleName(NamespaceName)), "ToHead"))), "(o.Item"), k + 1), ");"))
                        {
                            yield return(_Line == "" ? "" : "    " + _Line);
                        }
                        k += 1;
                        continue;
                    }
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "var Item"), k + 1), " = o.Item"), k + 1), ";"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                k += 1;
            }
            foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    return new "), TypeString), "("), String.Join(", ", Enumerable.Range(0, Elements.Count).Select(i => "Item" + (i + 1).ToInvariantString()))), ");"))
            {
                yield return(_Line);
            }
            yield return("}");
        }
Exemplo n.º 24
0
        /**
         * Returns response status code of the attempted login
         */
        public async Task <HttpStatusCode> LoginUser(String usernameEmail, String password)
        {
            if (!ServerConfig.Instance.IsConnectedToInternet())
            {
                return(HttpStatusCode.ServiceUnavailable);
            }

            // Get the profile controller instances
            UserController      userController      = UserController.Instance;
            ClinicianController clinicianController = ClinicianController.Instance;

            // Fetch the url and client from the server config class
            String     url    = ServerConfig.Instance.serverAddress;
            HttpClient client = ServerConfig.Instance.client;

            String queries = null;

            queries = $"?usernameEmail={usernameEmail}&password={password}";

            HttpContent content = new StringContent("");

            content.Headers.Add("device_id", AppCenter.GetInstallIdAsync().Result.ToString());
            HttpResponseMessage response;

            try
            {
                response = await client.PostAsync(url + "/login" + queries, content);
            } catch (HttpRequestException)
            {
                return(HttpStatusCode.ServiceUnavailable);
            }

            if (response.StatusCode == HttpStatusCode.OK)
            {
                string responseContent = await response.Content.ReadAsStringAsync();

                if (IsClinician(responseContent))
                {
                    Clinician loggedInClinician = JsonConvert.DeserializeObject <Clinician>(responseContent);
                    string    authToken         = response.Headers.GetValues("token").FirstOrDefault();

                    ClinicianController.Instance.Login(loggedInClinician, authToken);

                    Console.WriteLine("Logged in as (CLINICIAN)" + string.Join(String.Empty, clinicianController.LoggedInClinician.name));

                    // Created code to signifiy clinician login internally
                    return(HttpStatusCode.OK);
                }
                else if (IsUser(responseContent))
                {
                    // Login as the user
                    User loggedInUser = JsonConvert.DeserializeObject <User>(responseContent);
                    if (loggedInUser.dateOfDeath == null)
                    {
                        string authToken = response.Headers.GetValues("token").FirstOrDefault();
                        UserController.Instance.Login(loggedInUser, authToken);

                        Console.WriteLine("Logged in as (USER)" + String.Join(String.Empty, userController.LoggedInUser.name));

                        // OK code to signifiy user login internally
                        return(HttpStatusCode.OK);
                    }
                    else
                    {
                        return(HttpStatusCode.Conflict);
                    }
                }
                else
                {
                    // Must've attempted login as admin -> deny
                    return(HttpStatusCode.Unauthorized);
                }
            }
            else
            {
                Console.WriteLine(String.Format("Failed login (Server {0})", response.StatusCode));
                return(response.StatusCode);
            }
        }
Exemplo n.º 25
0
        public void RelativePath_Unit_ExplicitStringCastOperator_Optimal()
        {
            String[] nodes = new String[] { "sites", "Chad", "Greer" };
            Char separator = RelativePath.ForwardSlash;
            String instance = nodes.Join(separator);

            RelativePath actual = (RelativePath)instance;
            Assert.AreEqual(separator, actual.Separator);
            Assert.AreEqual(nodes.Length, actual.Nodes.Count());
            foreach (Int32 i in Enumerable.Range(0, nodes.Length)) {
                Assert.AreEqual(nodes[i], actual.Nodes.ElementAt(i));
            }
        }
Exemplo n.º 26
0
        void DefaultWriteLogFunction(
            String assembly,
            String tag,
            String channel,
            String type,
            String time,
            String[] lines)
        {
            if (!this.enabledLogChannels.Contains (channel)) return;

            String startString = String.Format (
                "[{3}][{1}][{0}][{2}] ",
                time,
                type,
                channel,
                tag);

            if (!String.IsNullOrWhiteSpace (assembly))
                startString = String.Format ("[{0}]{1}", assembly, startString);

            String customNewLine = Environment.NewLine + new String (' ', startString.Length);

            String formatedLine = lines
                .Join (customNewLine);

            String log = startString + formatedLine;

            Console.WriteLine (log);
        }
Exemplo n.º 27
0
 public static string Join <T>([NotNull, InstantHandle] this IEnumerable <T> values) =>
 // ReSharper disable once BuiltInTypeReferenceStyle
 StringEx.Join("", values);
Exemplo n.º 28
0
        public void RelativePath_Unit_InequalityOperator3_ObjAIsNull()
        {
            String[] nodes = new String[] { "sites", "Chad", "Greer" };
            Char separator = RelativePath.ForwardSlash;
            String objA = nodes.Join(separator);
            RelativePath objB = null;

            Boolean actual = objA != objB;
            Assert.AreEqual(true, actual);
        }
Exemplo n.º 29
0
 public static string Join <T>([NotNull, InstantHandle] this IEnumerable <T> values, [CanBeNull] string separator) =>
 // ReSharper disable once BuiltInTypeReferenceStyle
 StringEx.Join(separator, values);
Exemplo n.º 30
0
        public void RelativePath_Unit_ToString_RelativePathhasEmptyLastNode()
        {
            String[] nodes = new String[] { "sites", "Chad", "Greer", String.Empty };
            Char separator = RelativePath.ForwardSlash;
            RelativePath target = new RelativePath(nodes, separator);

            String actual = target.ToString();
            Assert.AreEqual(nodes.Join(separator), actual);
        }
Exemplo n.º 31
0
        public void PhoneNumber_Unit_Equals1_ObjIsDifferentType()
        {
            String countryCode = "1";
            String areaCode = "800";
            String[] subscriberNumberGroups = new String[] { "867", "5309" };
            PhoneNumber target = new PhoneNumber(countryCode, areaCode, subscriberNumberGroups);
            Object obj = countryCode + " " + areaCode + " " + subscriberNumberGroups.Join(' ');

            Boolean actual = target.Equals(obj);
            Assert.AreEqual(false, actual);
        }
Exemplo n.º 32
0
        public IEnumerable <String> Module(ModuleDecl m)
        {
            foreach (var _Line in Combine(Combine(Begin(), "class "), GetEscapedIdentifier(m.Name)))
            {
                yield return(_Line);
            }
            yield return("{");

            yield return("private:");

            foreach (var f in m.Functions)
            {
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "std::function<"), f.ReturnValue.ToString()), "(Niveum::Expression::ExpressionParameterContext &)> "), GetEscapedIdentifier(Combine(Combine(Begin(), "Func_"), f.Name))), ";"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
            }
            yield return("");

            yield return("public:");

            foreach (var _Line in Combine(Combine(Combine(Begin(), "    "), GetEscapedIdentifier(m.Name)), "(std::shared_ptr<Niveum::ExpressionSchema::ModuleDef> md)"))
            {
                yield return(_Line);
            }
            yield return("    {");

            yield return("        std::unordered_map<std::u16string, std::shared_ptr<Niveum::ExpressionSchema::Expr>> fd;");

            yield return("        for (auto _f_ : md->Functions)");

            yield return("        {");

            yield return("            fd[_f_->Name] = _f_->Body;");

            yield return("        }");

            foreach (var f in m.Functions)
            {
                yield return("        " + "{");

                foreach (var _Line in Combine(Combine(Combine(Begin(), "    auto Body = fd["), GetEscapedStringLiteral(f.Name)), "];"))
                {
                    yield return(_Line == "" ? "" : "        " + _Line);
                }
                yield return("        " + "");

                yield return("        " + "    Niveum::Expression::ExpressionParameterTypeProvider eptp;");

                foreach (var p in f.Parameters)
                {
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "eptp.Parameters["), GetEscapedStringLiteral(p.Name)), "] = Niveum::ExpressionSchema::PrimitiveType::"), p.Type.ToString()), ";"))
                    {
                        yield return(_Line == "" ? "" : "            " + _Line);
                    }
                }
                yield return("        " + "    Niveum::Expression::ExpressionCalculator ec;");

                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    "), GetEscapedIdentifier(Combine(Combine(Begin(), "Func_"), f.Name))), " = ec.BuildExpression<"), f.ReturnValue.ToString()), ">(eptp, Body);"))
                {
                    yield return(_Line == "" ? "" : "        " + _Line);
                }
                yield return("        " + "}");
            }
            yield return("    }");

            yield return("");

            foreach (var f in m.Functions)
            {
                var ParameterList = String.Join(", ", f.Parameters.Select(p => p.Type.ToString() + " " + GetEscapedIdentifier(p.Name)));
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Begin(), f.ReturnValue.ToString()), " "), GetEscapedIdentifier(f.Name)), "("), ParameterList), ")"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                yield return("    " + "{");

                yield return("    " + "    Niveum::Expression::ExpressionParameterContext epc;");

                foreach (var p in f.Parameters)
                {
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "epc.Parameters["), GetEscapedStringLiteral(p.Name)), "] = "), GetEscapedIdentifier(p.Name)), ";"))
                    {
                        yield return(_Line == "" ? "" : "        " + _Line);
                    }
                }
                foreach (var _Line in Combine(Combine(Combine(Begin(), "    return "), GetEscapedIdentifier(Combine(Combine(Begin(), "Func_"), f.Name))), "(epc);"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                yield return("    " + "}");
            }
            yield return("};");
        }
Exemplo n.º 33
0
        public void RelativePath_Unit_Equals3_ObjIsEqualString()
        {
            String[] nodes = new String[] { "sites", "Chad", "Greer" };
            Char separator = RelativePath.ForwardSlash;
            RelativePath target = new RelativePath(nodes, separator);
            String other = nodes.Join(separator);

            Boolean actual = target.Equals(other);
            Assert.AreEqual(true, actual);
        }
Exemplo n.º 34
0
        public void RelativePath_Unit_InequalityOperator2_EqualObjects()
        {
            String[] nodes = new String[] { "sites", "Chad", "Greer" };
            Char separator = RelativePath.ForwardSlash;
            RelativePath objA = new RelativePath(nodes, separator);
            String objB = nodes.Join(separator);

            Boolean actual = objA != objB;
            Assert.AreEqual(false, actual);
        }
Exemplo n.º 35
0
        public IEnumerable <String> Module(ModuleDecl m)
        {
            foreach (var _Line in Combine(Combine(Begin(), "public class "), GetEscapedIdentifier(m.Name)))
            {
                yield return(_Line);
            }
            yield return("{");

            foreach (var f in m.Functions)
            {
                foreach (var _Line in Combine(Combine(Begin(), "private class "), GetEscapedIdentifier(Combine(Combine(Begin(), "FuncContext_"), f.Name))))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                yield return("    " + "{");

                foreach (var p in f.Parameters)
                {
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "public "), p.Type.ToString()), " "), GetEscapedIdentifier(p.Name)), ";"))
                    {
                        yield return(_Line == "" ? "" : "        " + _Line);
                    }
                }
                yield return("    " + "}");

                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "private Func<"), GetEscapedIdentifier(Combine(Combine(Begin(), "FuncContext_"), f.Name))), ", "), f.ReturnValue.ToString()), "> "), GetEscapedIdentifier(Combine(Combine(Begin(), "Func_"), f.Name))), ";"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
            }
            yield return("");

            foreach (var _Line in Combine(Combine(Combine(Begin(), "    public "), GetEscapedIdentifier(m.Name)), "(ModuleDef md)"))
            {
                yield return(_Line);
            }
            yield return("    {");

            yield return("        var fd = md.Functions.ToDictionary(_f_ => _f_.Name);");

            foreach (var f in m.Functions)
            {
                yield return("        " + "{");

                foreach (var _Line in Combine(Combine(Combine(Begin(), "    var vc = new VariableContext<"), GetEscapedIdentifier(Combine(Combine(Begin(), "FuncContext_"), f.Name))), ">();"))
                {
                    yield return(_Line == "" ? "" : "        " + _Line);
                }
                foreach (var p in f.Parameters)
                {
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "vc.Replace("), GetEscapedStringLiteral(p.Name)), ", null, PrimitiveType."), p.Type.ToString()), ", vvc => (Func<"), GetEscapedIdentifier(Combine(Combine(Begin(), "FuncContext_"), f.Name))), ", "), p.Type.ToString()), ">)("), GetEscapedIdentifier(Combine(Combine(Begin(), "Context_"), f.Name))), " => "), GetEscapedIdentifier(Combine(Combine(Combine(Combine(Begin(), "Context_"), f.Name), "."), p.Name))), "));"))
                    {
                        yield return(_Line == "" ? "" : "            " + _Line);
                    }
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    var p = new VariableProviderCombiner<"), GetEscapedIdentifier(Combine(Combine(Begin(), "FuncContext_"), f.Name))), ">(vc, new ExpressionRuntimeProvider<"), GetEscapedIdentifier(Combine(Combine(Begin(), "FuncContext_"), f.Name))), ">());"))
                {
                    yield return(_Line == "" ? "" : "        " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "    var d = ExpressionEvaluator<"), GetEscapedIdentifier(Combine(Combine(Begin(), "FuncContext_"), f.Name))), ">.Compile<"), f.ReturnValue.ToString()), ">(p, fd["), GetEscapedStringLiteral(f.Name)), "].Body);"))
                {
                    yield return(_Line == "" ? "" : "        " + _Line);
                }
                foreach (var _Line in Combine(Combine(Combine(Begin(), "    "), GetEscapedIdentifier(Combine(Combine(Begin(), "Func_"), f.Name))), " = t =>"))
                {
                    yield return(_Line == "" ? "" : "        " + _Line);
                }
                yield return("        " + "    {");

                yield return("        " + "        return d(t);");

                yield return("        " + "    };");

                yield return("        " + "}");
            }
            yield return("    }");

            yield return("");

            foreach (var f in m.Functions)
            {
                var ParameterList = String.Join(", ", f.Parameters.Select(p => p.Type.ToString() + " " + GetEscapedIdentifier(p.Name)));
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Combine(Begin(), "public "), f.ReturnValue.ToString()), " "), GetEscapedIdentifier(f.Name)), "("), ParameterList), ")"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                yield return("    " + "{");

                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    var "), GetEscapedIdentifier(Combine(Combine(Begin(), "Context_"), f.Name))), " = new "), GetEscapedIdentifier(Combine(Combine(Begin(), "FuncContext_"), f.Name))), "();"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                foreach (var p in f.Parameters)
                {
                    foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Combine(Begin(), GetEscapedIdentifier(Combine(Combine(Begin(), "Context_"), f.Name))), "."), GetEscapedIdentifier(p.Name)), " = "), GetEscapedIdentifier(p.Name)), ";"))
                    {
                        yield return(_Line == "" ? "" : "        " + _Line);
                    }
                }
                foreach (var _Line in Combine(Combine(Combine(Combine(Combine(Begin(), "    return "), GetEscapedIdentifier(Combine(Combine(Begin(), "Func_"), f.Name))), "("), GetEscapedIdentifier(Combine(Combine(Begin(), "Context_"), f.Name))), ");"))
                {
                    yield return(_Line == "" ? "" : "    " + _Line);
                }
                yield return("    " + "}");
            }
            yield return("}");
        }
Exemplo n.º 36
0
        static void Main(string[] args)
        {
            var cmds   = new CmdOptions();
            var parser = new Parser(with => with.HelpWriter = Console.Error);

            parser.ParseArguments <CmdOptions>(args)
            .WithParsed(o => cmds = o)
            .WithNotParsed(errs => Console.WriteLine("Unable to parse command line: {0}", String.Join(" ", args)));

            Configs.LoadConfigs();
            IoC.Bind(new Uuid());
            IoC.Bind(new Archiver());
            IoC.Bind(new Localization(ELanguage.English));

            if (!CheckArchiver(cmds.GameDir))
            {
                return;
            }

            if (cmds.CharacterDir != null)
            {
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;
                new NpcRefGenerator().SearchDir(cmds.CharacterDir);
            }
        }