public IActionResult Check(string checksum)
        {
            var model = new ChecksumViewModel();

            model.Checksum = checksum;

            //Get checksum info from storage
            var checksumStorage = NeoAPI.getStorage(NeoAPI.Net.Test, _scriptHash, checksum);

            if (checksumStorage != null && checksumStorage.Value != null)
            {
                string       checksumValue = checksumStorage.Value;
                ChecksumInfo checksumInfo  = ChecksumInfo.FromBytes(Encoding.ASCII.GetBytes(checksumValue));
                model.ChecksumInfo = checksumInfo;

                //Get address info from storage (based on address from checksum info)
                var addressStorage = NeoAPI.getStorage(NeoAPI.Net.Test, _scriptHash, checksumInfo.Address.AsString());
                if (addressStorage != null && addressStorage.Value != null)
                {
                    string      value       = addressStorage.Value;
                    AddressInfo addressInfo = AddressInfo.FromBytes(Encoding.ASCII.GetBytes(value));
                    model.AddressInfo = addressInfo;
                }
            }


            return(View(model));
        }
示例#2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="pdwFilePath"></param>
        /// <exception>FileNotExistException: the pdw file path is not exist</exception>
        /// <exception>NotIsOpenXmlFormatException: the pdw file not has openxml format</exception>
        /// <exception>NotIsPdwFormatException: the pdw file path not has pdw format</exception>
        public PdwReader(string pdwFilePath)
        {
            if (!File.Exists(pdwFilePath))
            {
                throw new FileNotExistException();
            }

            try
            {
                _filePath = pdwFilePath;
                _guid     = System.Guid.NewGuid().ToString();

                _checksum   = string.Empty;
                _internalBm = string.Empty;
                _osql       = string.Empty;
                _xslt       = string.Empty;

                _checksumInfo = null;

                if (!ReadCustomXmlparts())
                {
                    throw new NotIsPdwFormatException();
                }

                SetChecksumInfo();
            }
            catch
            {
                throw new NotIsOpenXmlFormatException();
            }
        }
        /// <summary>
        /// Add a new checksum
        /// </summary>
        /// <param name="address">Source address</param>
        /// <param name="checksum">New checksum</param>
        /// <param name="fileName">Filename</param>
        /// <returns></returns>
        private static bool New(byte[] address, string checksum, string fileName)
        {
            //Check if there is a checksum given
            if (checksum == null || checksum == "")
            {
                return(false);
            }

            //Check if there is a filename given
            if (fileName == null || fileName == "")
            {
                return(false);
            }

            //Check if the user using this contract is actually submitting his own address
            if (!Runtime.CheckWitness(address))
            {
                return(false);
            }

            //Check if this checksum already exists, overwrite is not possible
            var existing = Storage.Get(Storage.CurrentContext, address);

            if (existing == null)
            {
                return(false);
            }

            //Get current date
            Header header      = Blockchain.GetHeader(Blockchain.GetHeight());
            var    currentTime = header.Timestamp;

            //Save info about checksum: filename, address, date
            var info = new ChecksumInfo(address, currentTime, fileName);

            byte[] checksumInfo = ChecksumInfo.ToBytes(address, currentTime, fileName);
            Storage.Put(Storage.CurrentContext, checksum, checksumInfo);

            //Check if the creator already submitted a checksum before
            var existingInfo = Storage.Get(Storage.CurrentContext, GetFirstDateKey(checksum));

            if (existingInfo == null)
            {
                //Only insert first date if it's empty
                Storage.Put(Storage.CurrentContext, GetFirstDateKey(checksum), currentTime);
            }

            //Always set last updated date
            Storage.Put(Storage.CurrentContext, GetLastDateKey(checksum), currentTime);

            //TODO: Increase count of total number of checksums

            return(true);
        }
示例#4
0
 private void SetChecksumInfo()
 {
     try
     {
         if (_checksumInfo == null)
         {
             _checksumInfo = Utilities.Deserialize <ChecksumInfo>(_checksum);
             _checksumInfo.InternalBookmark = _internalBm;
             _checksumInfo.Osql             = _osql;
         }
     }
     catch { }
 }
示例#5
0
        public ChecksumInfo GetChecksum()
        {
            try
            {
                string          srvKey = string.Empty;
                ServicesProfile srvPro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out srvKey);
                GetPdwInformation(srvKey);
                Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(srvKey);
                List <XmlObject> customXmls = srvPro.XmlObjects;
                ChecksumInfo     checksum   = null;
                string           osql       = string.Empty;

                foreach (XmlObject xmlObject in customXmls)
                {
                    if (xmlObject == null)
                    {
                        continue;
                    }

                    if (xmlObject.ContentType == ContentType.Checksum)
                    {
                        checksum = ObjectSerializeHelper.Deserialize <ChecksumInfo>(xmlObject.Content);
                        checksum.InternalBookmark = GetInternalBookmarkString();
                        checksum.Osql             = osql;
                    }
                    else if (xmlObject.ContentType == ContentType.Osql)
                    {
                        osql = xmlObject.Content;
                        if (checksum != null)
                        {
                            checksum.Osql = osql;
                        }
                    }
                }

                return(checksum != null ? checksum : new ChecksumInfo());
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_GetChecksumError);
                newSrvExp.Errors.Add(srvExp);

                throw newSrvExp;
            }
            catch (Exception ex)
            {
                ServiceException srvExp = new ServiceException(ErrorCode.ipe_GetChecksumError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_GetChecksumError, ex.Message), ex.StackTrace);
                throw srvExp;
            }
        }
示例#6
0
        public void btnPreviewOsql_Click(Office.IRibbonControl control)
        {
            _isForceDisablePreviewOsql = false;
            Document doc = Wkl.MainCtrl.CommonCtrl.CommonProfile.ActiveDoc;

            try
            {
                //Validate document
                string mgrKey = string.Empty;
                Pdw.WKL.Profiler.Manager.ManagerProfile mgrPro = Wkl.MainCtrl.ManagerCtrl.CreateProfile(out mgrKey);
                mgrPro.WdColorIndex   = DefineColors.GetColor(selectedColor).Color;
                mgrPro.IsSaveDocument = false;

                ContextValidator validator = new ContextValidator(doc);
                validator.ValidateBeforeSave(mgrKey);

                //If document has invalid bookmarks
                if (!mgrPro.IsCorrect)
                {
                    //Ask user to remove invalid bookmarks
                    mgrPro.WDoc = doc;
                    Hcl.SaveMessageDialog saveNotify  = new Hcl.SaveMessageDialog(mgrKey);
                    DialogResult          userConfirm = saveNotify.ShowDialog();

                    if (userConfirm != DialogResult.OK || !HasSelectIBM())
                    {
                        return;
                    }
                }

                //Build and show osql
                PdwInfo pdwInfo = GetPdwInfo(doc);

                ChecksumInfo checkSum = ProntoDoc.Framework.Utils.ObjectSerializeHelper.Deserialize <ChecksumInfo>(pdwInfo.ChecksumString);
                OsqlXml      osqlXml = ProntoDoc.Framework.Utils.ObjectSerializeHelper.Deserialize <OsqlXml>(pdwInfo.OsqlString);
                string       renderArgument, jRenderArgument;
                GetRenderArguments(checkSum, out renderArgument, out jRenderArgument);

                Pdw.PreviewOsql.PreviewOsqlForm previewDialog = new Pdw.PreviewOsql.PreviewOsqlForm();
                previewDialog.Osql            = osqlXml.GetOsql("/*------------------------------------*/");
                previewDialog.JOsql           = osqlXml.GetJsql("/*------------------------------------*/");
                previewDialog.Xsl             = pdwInfo.XsltString;
                previewDialog.RenderArgument  = renderArgument;
                previewDialog.JRenderArgument = jRenderArgument;
                previewDialog.CheckSumInfo    = checkSum;
                previewDialog.OsqlXml         = osqlXml;
                previewDialog.ShowDialog();
            }
            catch { }
        }
示例#7
0
        /// <summary>
        /// Validate Internal Bookmark is match with any Domain. Key is full name of document
        /// </summary>
        /// <param name="fullDocName"></param>
        public void IsInternalBMMatchWithDomain(string key)
        {
            //1.Get InternalBM
            //2.Get Checksum information
            //3.Load Data from datasegment.
            //4.Check match
            try
            {
                IntegrationServiceProfile integrationProfile = Wkl.MainCtrl.ServiceCtrl.GetProfile(key).IntegrationService;
                TemplateInfo templateInfo = Wkl.MainCtrl.CommonCtrl.GetTemplateInfo(integrationProfile.TemplateFileName);

                string          srvKey = string.Empty;
                ServicesProfile srvPro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out srvKey);
                GetInternalBookmark(srvKey);
                templateInfo.InternalBookmark = srvPro.Ibm;
                templateInfo.UpdateDomainNames();
                templateInfo.PdeContent = srvPro.PdeContent;
                Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(srvKey);

                //Get Checksum Info.
                ChecksumInfo checksum = GetChecksum();

                integrationProfile.CheckMatchWithDomain_OListMatch = new List <DomainMatch>();
                integrationProfile.Result = true;
                foreach (InternalBookmarkDomain ibmDomain in templateInfo.InternalBookmark.InternalBookmarkDomains)
                {
                    DomainMatchItem domainMatchItem = IsMatchWithDataSegment(ibmDomain, ibmDomain.DomainName);
                    if (domainMatchItem != null && (!domainMatchItem.IsMatch || !domainMatchItem.IsMatchRelationOn)) // not match
                    {
                        DomainMatch domainMatch = FindTheNearestDomain(ibmDomain, domainMatchItem, ibmDomain.DomainName);
                        integrationProfile.CheckMatchWithDomain_OListMatch.Add(domainMatch);
                        integrationProfile.Result = false;
                    }
                }
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_ValidateIbmWithDomainError);
                newSrvExp.Errors.Add(srvExp);

                throw newSrvExp;
            }
            catch (Exception ex)
            {
                ServiceException srvExp = new ServiceException(ErrorCode.ipe_ValidateIbmWithDomainError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_ValidateIbmWithDomainError, ex.Message), ex.StackTrace);
                throw srvExp;
            }
        }
示例#8
0
        private void GetRenderArguments(ChecksumInfo checksum, out string renderArgument, out string jRenderArgument)
        {
            System.Text.StringBuilder renderArgBuilder  = new System.Text.StringBuilder();
            System.Text.StringBuilder jrenderArgBuilder = new System.Text.StringBuilder();

            foreach (ChecksumInfoItem item in checksum.ChecksumInfoItems)
            {
                string sysArg = ObjectSerializeHelper.SerializeToString <ProntoDoc.Framework.CoreObject.SystemParameter>(item.SystemParameter);
                string temp   = ObjectSerializeHelper.SerializeToString <RenderArgDomainSchema>(item.RenderArgument);
                temp = sysArg + Environment.NewLine + Environment.NewLine + Environment.NewLine + temp;
                renderArgBuilder.AppendLine(temp);

                temp = ObjectSerializeHelper.SerializeToString <JRenderArgDomainSchema>(item.JRenderArgument);
                jrenderArgBuilder.AppendLine(temp);
            }

            renderArgument  = renderArgBuilder.ToString();
            jRenderArgument = jrenderArgBuilder.ToString();
        }
示例#9
0
        public string GenChecksum(string osqlString, List <ChecksumInfoItem> checksumItems, TemplateType templateType,
                                  string dscColor, bool hasDsc, string filePath)
        {
            // 1. prepare service
            MainService mainService = new MainService();

            Integrity.Validator validatorService = new Integrity.Validator();

            // 2. Plugin Id
            string pluginId = Wkl.MainCtrl.CommonCtrl.CommonProfile.PluginInfo.Id + " | " + Wkl.MainCtrl.CommonCtrl.CommonProfile.PluginInfo.Version;

            // 3. Plugin Name
            string pluginName = Wkl.MainCtrl.CommonCtrl.CommonProfile.PluginInfo.Name;

            // 4. User name
            string userName = validatorService.GetCurrentUserName();

            // 5. Checksum content
            string strInternalBm = mainService.PropertyService.GetInternalBookmarkString();
            string strChecksum   = validatorService.GenCheckSum(pluginId, pluginName, userName, strInternalBm, osqlString);

            // 6. make checksum object
            ChecksumInfo objChecksum = new ChecksumInfo(pluginId, pluginName, userName, strChecksum);

            // 7. add other information
            objChecksum.ChecksumInfoItems = checksumItems;

            // 8. template type
            objChecksum.TemplateType = templateType;

            // 9. add computer name
            objChecksum.ComputerName = validatorService.GetComputerName();

            objChecksum.DocumentSpecificColor = dscColor;
            objChecksum.HasDocumentSpecific   = hasDsc;
            objChecksum.FilePath = filePath;

            return(ObjectSerializeHelper.SerializeToString <ChecksumInfo>(objChecksum));
        }
示例#10
0
        async Task <Download <SliceDownloadData> > DownloadSlice(Storage storage, string checksumUri, string headerUri, string dataUri, Func <FileStream, FileStream, FileStream, SliceDownloadData> callback)
        {
            var checksumStream = storage.FileTempStream();
            var headerStream   = storage.FileTempStream();
            var dataStream     = storage.FileTempStream();

            var delete = true;

            try
            {
                await DownloadToStream(checksumUri, checksumStream);
                await DownloadToStream(headerUri, headerStream);
                await DownloadToStream(dataUri, dataStream);

                checksumStream.Position = 0;
                var checksums = new ChecksumInfo(new Unpacker(checksumStream));
                checksumStream.Position = 0;
                headerStream.Position   = 0;
                dataStream.Position     = 0;

                var headerValid = checksums.Valid("header", headerStream);
                var dataValid   = checksums.Valid("data", dataStream);

                if (!headerValid || !dataValid)
                {
                    return(Download <SliceDownloadData> .InvalidChecksum);
                }

                delete = false;
                return(new Download <SliceDownloadData>(callback.Invoke(checksumStream, headerStream, dataStream)));
            }
            catch (Exception ex)
            {
                return(Download <SliceDownloadData> .HandleException(ex));
            }
            finally
            {
                checksumStream.Dispose();
                headerStream.Dispose();
                dataStream.Dispose();

                if (delete)
                {
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
                    try
                    {
                        File.Delete(checksumStream.Name);
                    }
                    catch { }

                    try
                    {
                        File.Delete(headerStream.Name);
                    }
                    catch { }

                    try
                    {
                        File.Delete(dataStream.Name);
                    }
                    catch { }

#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
                }
            }
        }