Ejemplo n.º 1
0
        /// <summary>
        /// Entry point for the VersionChecker API when the latest version number is stored in a JSON file at a given URL.
        /// </summary>
        /// <typeparam name="T">The type of the class which will be used for deserializing the JSON file.</typeparam>
        /// <param name="URL">The URL at which the JSON file containing the latest version number can be found.</param>
        /// <param name="versionProperty">The name of the property in <typeparamref name="T"/> which holds the version number.</param>
        /// <param name="currentVersion">A <see cref="Version"/> describing the current version number of the mod that is installed.
        /// Optional. By default, will be retrieved from the mod's assembly.</param>
        /// <param name="displayName">The display name to use for the mod. Optional. By default, will be retrieved from
        /// the mod's assembly.</param>
        public static void Check <T>(string URL, string versionProperty = "Version", Version currentVersion = null, string displayName = null)
            where T : class
        {
            Singleton();

            var assembly = Assembly.GetCallingAssembly();

            if (CheckedVersions.ContainsKey(assembly))
            {
                return;
            }

            currentVersion = currentVersion ?? assembly.GetName().Version;
            displayName    = displayName ?? assembly.GetName().Name;

            string prefix = null;

            if (assembly == Assembly.GetAssembly(typeof(VersionChecker)))
            {
                prefix = "[VersionChecker]";
            }
            else
            {
                prefix = $"[VersionChecker] [{displayName}]";
            }

            if (currentVersion == null)
            {
                Console.WriteLine($"{prefix} There was an error retrieving the current version.");
                return;
            }

            if (!CheckConnection(URL))
            {
                Console.WriteLine($"{prefix} Unable to check for updates: Connection unavailable.");
                return;
            }

            var latestVersion = GetLatestVersion <T>(URL, typeof(T).GetProperty(versionProperty));

            if (latestVersion == null)
            {
                Console.WriteLine($"{prefix} There was an error retrieving the latest version.");
                return;
            }

            var versionRecord = CheckedVersions[assembly] = new VersionRecord
            {
                DisplayName    = displayName,
                CurrentVersion = currentVersion,
                LatestVersion  = latestVersion,
                Colour         = GetColour()
            };

            Console.WriteLine($"{prefix} {VersionMessage(versionRecord)}");
        }
Ejemplo n.º 2
0
        private IEnumerator PrintOutdatedVersion(VersionRecord versionRecord)
        {
            if (IsOutdated(versionRecord))
            {
                for (var i = 0; i < 3; i++)
                {
                    ErrorMessage.AddError($"[<color={versionRecord.Colour}>{versionRecord.DisplayName}</color>] " +
                                          VersionMessage(versionRecord, true));

                    yield return(new WaitForSeconds(5));
                }
            }
        }
Ejemplo n.º 3
0
        public override Task <int> InvokeAsync(InvocationContext context)
        {
            var record = new VersionRecord(
                InformationalVersion,
                RepositoryUrl,
                BaseVersion.Major,
                BaseVersion.Minor,
                Commits,
                Branch,
                Commit,
                Sha,
                CommitDate);

            this.WriteHeader <VersionRecord>();
            this.Write <VersionRecord>(record);

            return(Task.FromResult(0));
        }
Ejemplo n.º 4
0
 private static string VersionMessage(VersionRecord versionRecord, bool splitLines = false)
 {
     if (IsOutdated(versionRecord))
     {
         return($"A new version has been released: v{versionRecord.LatestVersion.ToStringParsed()}." +
                (splitLines ? Environment.NewLine : " ") +
                $"Currently running v{versionRecord.CurrentVersion.ToString()}. " +
                "Please update at your earliest convenience!");
     }
     else if (IsAhead(versionRecord))
     {
         return($"Currently running v{versionRecord.CurrentVersion.ToStringParsed()}." +
                (splitLines ? Environment.NewLine : " ") +
                $"The latest release version is v{versionRecord.LatestVersion.ToStringParsed()}. " +
                $"We are ahead.");
     }
     else
     {
         return($"Currently running v{versionRecord.CurrentVersion.ToStringParsed()}. Up to date.");
     }
 }
Ejemplo n.º 5
0
 private static bool IsAhead(VersionRecord versionRecord) => versionRecord.CurrentVersion > versionRecord.LatestVersion &&
 versionRecord.CurrentVersion.ToStringParsed() != versionRecord.LatestVersion.ToStringParsed();
Ejemplo n.º 6
0
 public override void Read(VersionRecord verRec)
 {
 }
Ejemplo n.º 7
0
 public void Read(VersionRecord verRec)
 {
 }
Ejemplo n.º 8
0
 public void Read(VersionRecord verRec)
 {
     this.VerifyVersionRecord(verRec);
 }
Ejemplo n.º 9
0
 public void VerifyVersionRecord(VersionRecord verRec)
 {
     Verify(RecordType.Version, verRec.SequenceNo);
     Assert.AreEqual(sValuesStr.Dequeue(), verRec.Version);
 }
Ejemplo n.º 10
0
 public void Read(VersionRecord verRec)
 {
     Console.WriteLine("Version" + verRec.Version);
 }
Ejemplo n.º 11
0
        protected override void OnActivated()
        {
            base.OnActivated();

            Frame frame = Frame;
            View  view  = View;

            if (view == null)
            {
                return;
            }

            object        currentObject = view.CurrentObject;
            VersionRecord currentVR     = currentObject as VersionRecord;

            // <<< Проверка, когда контроллер должен работать
            this.Active[HideVersionServiceControllerReason] = true;

            if (currentObject == null || currentVR == null)
            {
                this.Active[HideVersionServiceControllerReason] = false;
                return;
            }

            if (Frame.Context.Name == TemplateContext.LookupControl || Frame.Context.Name == TemplateContext.LookupWindow)
            {
                this.Active[HideVersionServiceControllerReason] = false;
                return;
            }

            if ((frame as NestedFrame) != null | !view.IsRoot)
            {
                this.Active[HideVersionServiceControllerReason] = false;
                return;
            }

            //if (currentObject as IntecoAG.ERM.CS.IVersionBusinessLogicSupport == null) {
            //    this.Active[HideVersionServiceControllerReason] = false;
            //    return;
            //}

            //object currentObj = view.CurrentObject;

            // >>> Проверка, когда контроллер должен работать


            // Кнопка Новая версия
            //this.CreateNewVersionAction.Active.Clear();
            this.CreateNewVersionAction.Active[HideActionReason] = false;

            //if (currentVR.MainObject == null) {
            //    CreateNewVersionAction.Active[HideActionReason] = false;
            //}

            if (currentObject is IVersionBusinessLogicSupport)
            {
                this.CreateNewVersionAction.Active[HideActionReason] = true;

                if (currentVR.VersionState == VersionStates.VERSION_NEW)
                {
                    CreateNewVersionAction.Active[HideActionReason] = false;
                }

                //if (currentObj as IntecoAG.ERM.CS.IVersionSupport == null) {
                //    CreateNewVersionAction.Active[HideActionReason] = false;
                //}

                //} else {
                //    this.CreateNewVersionAction.Active[HideActionReason] = false;
            }



            // Кнопка Подвердить версию

            // Разбор, когда показывать кнопку
            // Если объект является главным для системы версий и имеется версия, которую можно утвердить

            VersionApprove.Active.Clear();

            if (currentVR.MainObject == null)
            {
                VersionApprove.Active[ApproveActionShowReason] = false;
                //return;
            }

            if (currentVR.MainObject as IVersionBusinessLogicSupport == null)
            {
                VersionApprove.Active[ApproveActionShowReason] = false;
                //return;
            }

            if (currentVR.VersionState != VersionStates.VERSION_PROJECT & currentVR.VersionState != VersionStates.VERSION_NEW)
            {
                VersionApprove.Active[ApproveActionShowReason] = false;
                //return;
            }
        }
Ejemplo n.º 12
0
        private void VersionApprove_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            View  view  = View;
            Frame frame = Frame;

            // Запускаем метод Approve текущего объекта
            VersionRecord currentObj = View.CurrentObject as VersionRecord;

            if (currentObj == null)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("Документ не поддерживает операцию утверждения");
                return;
            }

            IVersionBusinessLogicSupport mainObj = currentObj.MainObject as IVersionBusinessLogicSupport;

            if (mainObj == null)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("Документ не поддерживает операцию утверждения");
                return;
            }

            // Паша: добавил сохранение объекта перед Approve, иначе только что созданная версия не находиться в списке версий:(
            view.ObjectSpace.CommitChanges();
            mainObj.Approve(currentObj);
            view.ObjectSpace.CommitChanges();

            // Прежняя концепция (с SimpleContract и т.д.) предполагала, что главный объект показывается пользователю со списком
            // его версий. Новая концепция предполагает вместо показа главного объекта всегда показывать его Current версию, а если
            // таковой нет, то версию со статусом NEW.
            // Замечание. Наличие записи сос статусом NEW означает, что Currentу главного объекта и есть эта запись со статусом NEW


            //Type objType = (System.Type)((System.Reflection.MemberInfo)((mainObj).GetType()));
            //string DetailViewID = Application.FindDetailViewId(objType);

            //IObjectSpace objectSpace = frame.Application.CreateObjectSpace();
            //object passedDisplayedObject = objectSpace.GetObject(mainObj);


            // Основной объект:
            //object DisplayedObject = currentObj.MainObject;
            object DisplayedObject = (mainObj as crmContractDeal).Current;

            // Определяем DetailView
            string DetailViewId = frame.Application.FindDetailViewId(DisplayedObject.GetType());

            IObjectSpace objectSpace           = Application.CreateObjectSpace();
            object       passedDisplayedObject = objectSpace.GetObject(DisplayedObject);

            // Показываем
            //CommonMethods.ShowConcreteDetailViewInWindow(frame, objectSpace, DetailViewId, passedDisplayedObject, TargetWindow.Current);

            TargetWindow openMode = TargetWindow.Current;
            DetailView   dv       = frame.Application.CreateDetailView(objectSpace, DetailViewId, true, passedDisplayedObject);

            ShowViewParameters svp = new ShowViewParameters()
            {
                CreatedView = dv, TargetWindow = openMode, Context = TemplateContext.View, CreateAllControllers = true
            };

            e.ShowViewParameters.Assign(svp);
        }